package com.greenhouse9.prog01;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import com.greenhouse9.prog01.split.Command;
import com.greenhouse9.prog01.OptionSpec;

public class CommandProcess {

	private OptionSpec optionSpec;

	public void doProcess (String[] args){

		optionSpec = new OptionSpec ();
		optionSpec = optionSpecCreater ();
		//OptionSpec optionSpec = getOptionSpec ();
		Options options = optionSpec.getOpeions();

		CommandLineParser parser = new BasicParser ();

		Command cm = new Command();

		try {
			CommandLine cl = parser.parse(options, args);

			cm.setCommandLine(cl);
		}
		catch (ParseException e){
			HelpFormatter formatter = new HelpFormatter ();
			formatter.printHelp(optionSpec.getName(), options, true);
			System.exit(1);
		}

		if(cm.validate()==-1){
			cm.printError();
			System.exit(1);
		}
		else {
			cm.execute();
			System.exit(0);
		}
  	}

	protected OptionSpec optionSpecCreater(){
		return null;
	}
}
